package com.wxlsoft.utils;

import javax.swing.JProgressBar;

import com.wxlsoft.config.model.GenralConfigProperties;
import com.wxlsoft.excel.enums.HandlerConfigType;
import com.wxlsoft.ui.UiController;

public class UIContext {

	private static UiController uiController;
	private static JProgressBar progress;
	
	public static void register(UiController uiController) {
		UIContext.uiController = uiController;
	}

	public static GenralConfigProperties getConfig(HandlerConfigType ccType) {
		GenralConfigProperties properties = new GenralConfigProperties();
		properties.setConfigType(ccType);
		if (HandlerConfigType.ESB_PLATFORM == ccType) {
			properties.setEnv(uiController.apolloEnv.getText().trim());
			properties.setUsername(uiController.apolloUsername.getText().trim());
			properties.setPassword(uiController.apolloPassword.getText().trim());
			properties.setPortalUrl(uiController.apolloPortal.getText().trim());
		}
		return properties;
	}

	public static void setProgress(JProgressBar progress) {
		UIContext.progress = progress;
	}

	public static void incrementProgress(int count) {
		int value = UIContext.progress.getValue();
		if (value < 490) {
			UIContext.progress.setValue(value + count);
		}
	}
	
}
